package com.byl.sdk.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by niu on 2018/3/13.
 */
public class PageMap extends HashMap {

    private int page; //当前第几页

    private int pageSize; //每页记录数


    public int getPage() {
        if (page == 0)
            page = 1;
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        if (pageSize == 0)
            pageSize = 10;
        return pageSize;
    }



    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    @Override
    public void putAll(Map m) {
        if (null == m)
            m = new HashMap();
        this.page = 1;
        if (m.containsKey("page"))
            setPage(Integer.parseInt(m.get("page").toString()));
        if (m.containsKey("pageSize"))
            setPageSize(Integer.parseInt(m.get("pageSize").toString()));
        int offset = (getPage() - 1) * getPageSize();
        m.put("offset", offset);
        m.put("pageSize", getPageSize());
        super.putAll(m);
    }

    public PageMap() {
    }

    public PageMap(Map m) {
        putAll(m);
    }

}
